<template>
    <div class="login-outer">
    <i-form v-ref:form-inline :model="formInline" :rules="ruleInline">
        <Form-item prop="password">
            <i-input type="password" :value.sync="formInline.oldPassword" placeholder="请输入原密码">
                <Icon type="ios-locked-outline" slot="prepend"></Icon>
            </i-input>
        </Form-item>
        <Form-item prop="password">
            <i-input type="password" :value.sync="formInline.password" placeholder="请输入新密码">
                <Icon type="ios-locked-outline" slot="prepend"></Icon>
            </i-input>
        </Form-item>
        <Form-item>
            <i-button type="primary" @click="handleSubmit('formInline')">修改密码</i-button>
        </Form-item>
    </i-form>
    </div>
</template>
<script>
    export default {
        data () {
            return {
                formInline: {
                    password:'',
                    oldPassword: '',
                },
            }
        },
        methods: {
            handleSubmit(name) {
                const that=this;
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.$http.jsonp(this.path+'user/userServlet/editPwd',{
                                params:{oldPass:this.formInline.oldPassword,newPass:this.formInline.password,},
                                jsonp:'callback'
                            }).then((datas)=>{
                                if(datas.body.code=='001'){    
                                    that.myRouter.go({path:'/app/home'});
                                    this.$Message.success('密码修改成功!');
                                }else if(datas.body.code=='002'){
                                    this.$Message.error('密码修改失败!');
                                }else if(datas.body.code=='003'){
                                    this.$Message.error('原密码错误!');
                                }
                            },(error)=>{
                                this.$Message.error('提交失败!');
                            });    
                    } else {
                        this.$Message.error('表单验证失败!');
                    }
                })
            },
            
            
        }
    }
</script>
<style>
    .login-outer{
        width:30%;
        position:relative;
        top:200px;
        margin:0 auto;
        text-align: center;
    }
</style>
